package com.healthy.support.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.support.domain.Sessions;
import com.healthy.support.service.ISessionsService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 聊天会话Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Sessions")
public class SessionsController extends BaseController
{
    @Autowired
    private ISessionsService sessionsService;

    /**
     * 查询聊天会话列表
     */
    @RequiresPermissions("support:Sessions:list")
    @GetMapping("/list")
    public TableDataInfo list(Sessions sessions)
    {
        startPage();
        List<Sessions> list = sessionsService.selectSessionsList(sessions);
        return getDataTable(list);
    }

    /**
     * 导出聊天会话列表
     */
    @RequiresPermissions("support:Sessions:export")
    @Log(title = "聊天会话", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sessions sessions)
    {
        List<Sessions> list = sessionsService.selectSessionsList(sessions);
        ExcelUtil<Sessions> util = new ExcelUtil<Sessions>(Sessions.class);
        util.exportExcel(response, list, "聊天会话数据");
    }

    /**
     * 获取聊天会话详细信息
     */
    @RequiresPermissions("support:Sessions:query")
    @GetMapping(value = "/{sessionId}")
    public AjaxResult getInfo(@PathVariable("sessionId") Long sessionId)
    {
        return success(sessionsService.selectSessionsBySessionId(sessionId));
    }

    /**
     * 新增聊天会话
     */
    @RequiresPermissions("support:Sessions:add")
    @Log(title = "聊天会话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sessions sessions)
    {
        return toAjax(sessionsService.insertSessions(sessions));
    }

    /**
     * 修改聊天会话
     */
    @RequiresPermissions("support:Sessions:edit")
    @Log(title = "聊天会话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sessions sessions)
    {
        return toAjax(sessionsService.updateSessions(sessions));
    }

    /**
     * 删除聊天会话
     */
    @RequiresPermissions("support:Sessions:remove")
    @Log(title = "聊天会话", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sessionIds}")
    public AjaxResult remove(@PathVariable Long[] sessionIds)
    {
        return toAjax(sessionsService.deleteSessionsBySessionIds(sessionIds));
    }
}
